<template>
  <div class="charts"></div>
</template>

<script>
import * as echarts from "echarts";
export default {
  props: {
    echartsData: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      myChart: "",
    };
  },
  created() {},
  mounted() {
    this.bindResizeEvent();
    setTimeout(() => {
      // console.log(this.echartsData);
      this.initChart();
    },1000)
  },
  updated() {
    this.chart.resize();
  },
  methods: {
    initChart() {
      this.myChart = echarts.init(document.querySelector(".charts"));
      const option = {
        title: {
          text: "鉴别评估危机等级人数分布",
          left: "center",
        },

        xAxis: {
          type: "category",
          boundaryGap: true,
          data: ["暂无", "较低", "中等", "较高", "极高"],
          name: "危机等级",
          axisTick: {
            alignWithLabel: true,
          },
        },
        yAxis: {
          type: "value",
          name: "人数",
          // axisLabel: {
          //   formatter: "{value} °C",
          // },
          min: -1,
          max: 1,
          interval: 1,
        },
        series: [
          {
            name: "危机等级人数",
            type: "line",
            data: this.echartsData,
          },
        ],
      };
      this.myChart.setOption(option);
    },

    bindResizeEvent() {
      window.addEventListener("resize", this.resize);
    },
    resize() {
      this.myChart.resize();
    },
  },
};
</script>

<style scoped>
.charts {
  width: 100%;
  height: 20rem;
}
</style>